<template>
	<view>
		<!-- 列表项 -->
		<view class="goods-item">
		  <!-- 左侧图片 -->
		  <view class="goods-item-left">
        <radio @click="radioClickHandler" :checked="goods.goods_state===2 ? true : false"  color="#c00000" v-if="showRadio"></radio>
		    <image class="goods-pic" :src="goods.goods_small_logo || defaultPic" mode=""></image>
		  </view>
		  <!-- 右侧数据  -->
		  <view class="goods-item-right">
		    <view class="goods-name">{{goods.goods_name}}</view>
		    <view class="goods-box">
		      <view class="goods-info">￥{{goods.goods_price | tofixed}}</view>
          <!-- 数字输入框 -->
          <uni-number-box @change="numChangeHandler" :min="1" :value="goods.goods_count" v-if="showRadio"></uni-number-box>
		    </view>
		  </view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"my-goods",
		data() {
			return {
				// 默认图片
				defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
			};
		},
    props:{
      goods: {
        type: Object,
        default: {}
      },
      showRadio: {
        type: Boolean,
        default: false
      },
    },
    methods: {
      // 点击是否选择商品
      radioClickHandler () {
        // 触发外界的（cart）的 radio-changed 事件
        this.$emit('radio-changed', {
          // 商品id
          goods_id: this.goods.goods_id,
          // 商品是否选中状态
          goods_state:this.goods.goods_state
        })
      },
      // 数字输入框改变事件
      numChangeHandler (val) {
        // 触发外界的（cart）的 num-cahnge 事件
        this.$emit('num-change', {
          // 商品id
          goods_id: this.goods.goods_id,
          // 商品数量
          goods_count: +val
        })
      }
    },
    filters: {
      tofixed(num) {
        return Number(num).toFixed(2)
      }
    }
	}
</script>

<style lang="scss">
.goods-item {
    display: flex;
    padding: 10px 5px;
    border-bottom: 1px solid #eee;
    .goods-item-left {
      margin-right: 5px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .goods-pic {
        width: 100px;
        height: 100px;
        display: block;
      }
    }
    .goods-item-right{
      display: flex;
      flex: 1;
      flex-direction: column;
      justify-content: space-between;
      .goods-name{
        font-size: 13px;
      }
      .goods-box{
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
      .goods-info {
        font-size: 15px;
        color: #C00000;
        font-weight: bold;
      }
    }
  }
  
</style>
